<template>
    <div>
        <div id="slider" class="mui-slider">
            <div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted" data-scroll="1">
                <div class="mui-scroll" style="transform: translate3d(0px, 0px, 0px) translateZ(0px); transition-duration: 0ms;">
                    <a :class="['mui-control-item', item.id == 0 ? 'mui-active' : '']" v-for="item in titleArr" :key="item.id" @click="getImage(item.id)">
                        {{item.title}}
                    </a>

                </div>
            </div>

        </div>
        <ul class="photo-list">
            <router-link v-for="item in imageArr" :key="item._id" tag="li" :to="'/home/photoInfo/'+item.id">
                <img v-lazy="item.img_url" >
                <div class="info">
                    <h1 class="info-title">{{item.title}}</h1>
                    <div class="info-body">{{item.zhaiyao}}</div>
                </div>
            </router-link>
        </ul>
    </div>
</template>

<script>
    import mui from '../../lib/dist/js/mui.js'
    import { Toast } from 'mint-ui'

    export default {
        data(){
            return {
                titleArr:[],
                imageArr:[],
            }
        },
        created(){
            this.getTitle();
            this.getImage(0);
        },
        mounted(){


        },
        updated(){
            mui(".mui-scroll-wrapper").scroll({
                deceleration: 0.0006 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
            });
        },
        methods:{
            getTitle(){
                //标题是死数据，并没有进行持久化
                this.$http.get('http://127.0.0.1:3001/getTitle').then((result)=>{
                    if(result.body.code === '0'){
                        //成功操作
                        this.titleArr = result.body.message;
                        this.titleArr.unshift({id:0,title:'全部'});
                    }else{
                        //失败操作
                        Toast('您的网络抽风了');
                    }
                }).catch(function (err) {
                    console.log(err);
                })
            },
            getImage(cateid){
                this.$http.get('http://127.0.0.1:3001/getImage?cateid='+cateid).then((result)=>{
                    if(result.body.code === '0'){
                        this.imageArr = result.body.images;
                        console.log(this.imageArr)
                    }else{
                        Toast('您的网络抽风了');
                    }
                }).catch(function (err) {
                    console.log(err);
                })
            }
        }

    }
</script>

<style scoped lang="less">
    * { touch-action: pan-y; }
    .photo-list{
        list-style: none;
        margin: 0;
        padding: 10px;
        li{
            margin-bottom: 10px;
            text-align: center;
            box-shadow: 0 0 9px #999;
            position: relative;
            img{
                width: 100%;
                height: 200px;
                vertical-align: middle;
            }
            img[lazy="loading"] {
                width: 40px;
                height: 300px;
                margin: auto;
            }
            .info{
                color: white;
                text-align: left;
                position: absolute;
                bottom: 0;
                left: 0;
                background-color: rgba(0, 0, 0, 0.4);
                max-height: 54px;
                h1{
                    font-size: 14px;
                }
                .info-body{
                    font-size: 13px;
                }

            }
        }
    }
</style>